<%@ page pageEncoding="utf-8"%>
<%@ include file="/common/import.jsp"%>
<%!
	public Integer CLINIC = 1; // 门诊类型

	// 新增满意度
	String create(Satisfaction satisfaction){
		Message msg = new Message(0);
		if(!"[]".equals(satisfaction.getImgs())) {
			String[] imgs = satisfaction.getImgs().split("\\|");
			if (imgs.length > 3) {
				msg = new Message(30097, "最多添加三张图片");
				return msg.toJson();
			}
			List<String> imgList = new ArrayList<String>();
			for (String img : imgs) {
				imgList.add(img);
			}
			satisfaction.setImgs(GsonUtil.toJson(imgList));
		}
		Integer id = createItem(satisfaction);
		if (id == null) {
			msg = new Message(30098, "操作失败");
			return msg.toJson();
		}
		return msg.toJson();
	}

	// 查询满意度
	String list(Input input){
		Message msg = new Message(0);
		Integer pageNum = 1; // 当前页
		Integer itemCount = 20; // 每页显示条数
		Integer hospital = input.getInt("hospital", -1);
		Integer oid = input.getInt("oid", -1);
		Integer category = input.getInt("category", -1);
		String sinceID = input.getDesc("since_id", ""); // 上一页
		String maxID = input.getDesc("max_id", ""); // 下一页
		String order = "desc"; // 降序
		String id = "";
		if (!sinceID.isEmpty()) {
			id = "id >" + sinceID;
			order = "asc";
		} else {
			id = "id <" + maxID;
		}
		String content = "new map(id as ID, parent as parent, uid as uid, name as name, phone as phone, oid as oid, score as score, idea as idea, client as client, category as category, imgs as imgs)";
		Where where = new Where("hospital=", hospital).and("status=", "1");
		if (oid != -1) {
			where.and("oid=", oid);
		}
		if (category != -1) {
			where.and("category=", category);
		}
		List list = QBuilder.db("basedb").select(content).from("Satisfaction").where(where.and(id)).order("id", order).query().getResultObj();
		if (list.size() == 0) {
			setErrcode(msg, NO_RESULT);
			return msg.toJson();
		}
		if ("asc".equals(order)) {
			Collections.reverse(list);
		}
		msg.put("list", list);
		return msg.toJson();
	}
%>
